<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Java基础 | 自由·生活</title>
    <meta name="generator" content="VuePress 1.5.4">
    <link rel="icon" href="images/favicon.ico">
    <script language="javascript" type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="/js/MouseClickEffect.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css">
    <meta name="description" content="脱离生存而生活，寻求自由">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    <link rel="preload" href="/assets/css/0.styles.8c3033ea.css" as="style"><link rel="preload" href="/assets/js/app.0e76bb72.js" as="script"><link rel="preload" href="/assets/js/3.c5829877.js" as="script"><link rel="preload" href="/assets/js/1.695f3f80.js" as="script"><link rel="preload" href="/assets/js/230.f895ca67.js" as="script"><link rel="prefetch" href="/assets/js/10.fdc11bc7.js"><link rel="prefetch" href="/assets/js/100.3e29fa54.js"><link rel="prefetch" href="/assets/js/101.19f861f4.js"><link rel="prefetch" href="/assets/js/102.0eb344c2.js"><link rel="prefetch" href="/assets/js/103.167b5aab.js"><link rel="prefetch" href="/assets/js/104.3463b648.js"><link rel="prefetch" href="/assets/js/105.fc782f3d.js"><link rel="prefetch" href="/assets/js/106.b2d60f6a.js"><link rel="prefetch" href="/assets/js/107.91f5548b.js"><link rel="prefetch" href="/assets/js/108.8bcbfcd7.js"><link rel="prefetch" href="/assets/js/109.a0dd87a3.js"><link rel="prefetch" href="/assets/js/11.5d72653a.js"><link rel="prefetch" href="/assets/js/110.8d3b5064.js"><link rel="prefetch" href="/assets/js/111.6e109181.js"><link rel="prefetch" href="/assets/js/112.7130a6e7.js"><link rel="prefetch" href="/assets/js/113.6c962a0e.js"><link rel="prefetch" href="/assets/js/114.82175aae.js"><link rel="prefetch" href="/assets/js/115.a83e6a2d.js"><link rel="prefetch" href="/assets/js/116.70ebc8b4.js"><link rel="prefetch" href="/assets/js/117.368509d0.js"><link rel="prefetch" href="/assets/js/118.54fdc470.js"><link rel="prefetch" href="/assets/js/119.64d2a2a3.js"><link rel="prefetch" href="/assets/js/12.bfde6b78.js"><link rel="prefetch" href="/assets/js/120.5b47488f.js"><link rel="prefetch" href="/assets/js/121.82865d4b.js"><link rel="prefetch" href="/assets/js/122.619e60ca.js"><link rel="prefetch" href="/assets/js/123.66c3fb26.js"><link rel="prefetch" href="/assets/js/124.4381768b.js"><link rel="prefetch" href="/assets/js/125.2f39619b.js"><link rel="prefetch" href="/assets/js/126.0c622bc6.js"><link rel="prefetch" href="/assets/js/127.caee15ee.js"><link rel="prefetch" href="/assets/js/128.99714900.js"><link rel="prefetch" href="/assets/js/129.ff59083b.js"><link rel="prefetch" href="/assets/js/13.2b3528b1.js"><link rel="prefetch" href="/assets/js/130.76df0e89.js"><link rel="prefetch" href="/assets/js/131.2333a328.js"><link rel="prefetch" href="/assets/js/132.65cff4f4.js"><link rel="prefetch" href="/assets/js/133.2c0991bc.js"><link rel="prefetch" href="/assets/js/134.fe5fc3a5.js"><link rel="prefetch" href="/assets/js/135.aef0a809.js"><link rel="prefetch" href="/assets/js/136.90fd1b1d.js"><link rel="prefetch" href="/assets/js/137.07750a3f.js"><link rel="prefetch" href="/assets/js/138.723bd2c0.js"><link rel="prefetch" href="/assets/js/139.d22450b7.js"><link rel="prefetch" href="/assets/js/14.b769124c.js"><link rel="prefetch" href="/assets/js/140.1659de26.js"><link rel="prefetch" href="/assets/js/141.f713c5ec.js"><link rel="prefetch" href="/assets/js/142.63ebd83f.js"><link rel="prefetch" href="/assets/js/143.404a833f.js"><link rel="prefetch" href="/assets/js/144.3e0107ef.js"><link rel="prefetch" href="/assets/js/145.cef80531.js"><link rel="prefetch" href="/assets/js/146.c68d17d7.js"><link rel="prefetch" href="/assets/js/147.0af3acbb.js"><link rel="prefetch" href="/assets/js/148.9f0d2452.js"><link rel="prefetch" href="/assets/js/149.28785960.js"><link rel="prefetch" href="/assets/js/15.7c3421d9.js"><link rel="prefetch" href="/assets/js/150.bf310c33.js"><link rel="prefetch" href="/assets/js/151.de6313cc.js"><link rel="prefetch" href="/assets/js/152.91a567b5.js"><link rel="prefetch" href="/assets/js/153.cfe26382.js"><link rel="prefetch" href="/assets/js/154.047349d0.js"><link rel="prefetch" href="/assets/js/155.6923503c.js"><link rel="prefetch" href="/assets/js/156.2443e22f.js"><link rel="prefetch" href="/assets/js/157.fac2fc32.js"><link rel="prefetch" href="/assets/js/158.3d470963.js"><link rel="prefetch" href="/assets/js/159.9512719e.js"><link rel="prefetch" href="/assets/js/16.baa49355.js"><link rel="prefetch" href="/assets/js/160.1a610cc3.js"><link rel="prefetch" href="/assets/js/161.b240977c.js"><link rel="prefetch" href="/assets/js/162.cfb78d5a.js"><link rel="prefetch" href="/assets/js/163.3c935aea.js"><link rel="prefetch" href="/assets/js/164.0188664b.js"><link rel="prefetch" href="/assets/js/165.6f4ba8e0.js"><link rel="prefetch" href="/assets/js/166.32b92de7.js"><link rel="prefetch" href="/assets/js/167.1087cc58.js"><link rel="prefetch" href="/assets/js/168.7e81ac69.js"><link rel="prefetch" href="/assets/js/169.5270c30b.js"><link rel="prefetch" href="/assets/js/17.2270e174.js"><link rel="prefetch" href="/assets/js/170.1d6bc941.js"><link rel="prefetch" href="/assets/js/171.e3781bc6.js"><link rel="prefetch" href="/assets/js/172.54d7bc4b.js"><link rel="prefetch" href="/assets/js/173.a88f9e1f.js"><link rel="prefetch" href="/assets/js/174.7d882351.js"><link rel="prefetch" href="/assets/js/175.7a0c6feb.js"><link rel="prefetch" href="/assets/js/176.12b22e86.js"><link rel="prefetch" href="/assets/js/177.b2230eac.js"><link rel="prefetch" href="/assets/js/178.023ba5be.js"><link rel="prefetch" href="/assets/js/179.53fa03a8.js"><link rel="prefetch" href="/assets/js/18.988151ff.js"><link rel="prefetch" href="/assets/js/180.f17c3614.js"><link rel="prefetch" href="/assets/js/181.8872481a.js"><link rel="prefetch" href="/assets/js/182.c57e38bc.js"><link rel="prefetch" href="/assets/js/183.7085d12e.js"><link rel="prefetch" href="/assets/js/184.aa164e5b.js"><link rel="prefetch" href="/assets/js/185.b7ed0f6b.js"><link rel="prefetch" href="/assets/js/186.f08304c9.js"><link rel="prefetch" href="/assets/js/187.4a10e63d.js"><link rel="prefetch" href="/assets/js/188.f0463437.js"><link rel="prefetch" href="/assets/js/189.cff969e0.js"><link rel="prefetch" href="/assets/js/19.c196a261.js"><link rel="prefetch" href="/assets/js/190.adc3524b.js"><link rel="prefetch" href="/assets/js/191.a14895a8.js"><link rel="prefetch" href="/assets/js/192.e595f819.js"><link rel="prefetch" href="/assets/js/193.3cbcef2c.js"><link rel="prefetch" href="/assets/js/194.55530a96.js"><link rel="prefetch" href="/assets/js/195.1a834f79.js"><link rel="prefetch" href="/assets/js/196.001dd10b.js"><link rel="prefetch" href="/assets/js/197.4b9de142.js"><link rel="prefetch" href="/assets/js/198.955a06ea.js"><link rel="prefetch" href="/assets/js/199.9d63eea7.js"><link rel="prefetch" href="/assets/js/20.74b35545.js"><link rel="prefetch" href="/assets/js/200.8fe0777d.js"><link rel="prefetch" href="/assets/js/201.a91425c3.js"><link rel="prefetch" href="/assets/js/202.5b89464a.js"><link rel="prefetch" href="/assets/js/203.e48d18e2.js"><link rel="prefetch" href="/assets/js/204.6cbc5c79.js"><link rel="prefetch" href="/assets/js/205.d26879e9.js"><link rel="prefetch" href="/assets/js/206.fd8688f3.js"><link rel="prefetch" href="/assets/js/207.ef25eb3d.js"><link rel="prefetch" href="/assets/js/208.9f0e5ab2.js"><link rel="prefetch" href="/assets/js/209.cbd7c763.js"><link rel="prefetch" href="/assets/js/21.3cbc9110.js"><link rel="prefetch" href="/assets/js/210.6b733c20.js"><link rel="prefetch" href="/assets/js/211.2b986a0a.js"><link rel="prefetch" href="/assets/js/212.faee0dc6.js"><link rel="prefetch" href="/assets/js/213.7ed75653.js"><link rel="prefetch" href="/assets/js/214.825d2d93.js"><link rel="prefetch" href="/assets/js/215.251aa760.js"><link rel="prefetch" href="/assets/js/216.11962b03.js"><link rel="prefetch" href="/assets/js/217.62e3335a.js"><link rel="prefetch" href="/assets/js/218.a7c3b793.js"><link rel="prefetch" href="/assets/js/219.5ff63a4c.js"><link rel="prefetch" href="/assets/js/22.d2507cce.js"><link rel="prefetch" href="/assets/js/220.28ea20d6.js"><link rel="prefetch" href="/assets/js/221.6108e4e1.js"><link rel="prefetch" href="/assets/js/222.73443d85.js"><link rel="prefetch" href="/assets/js/223.e115734d.js"><link rel="prefetch" href="/assets/js/224.499e0bab.js"><link rel="prefetch" href="/assets/js/225.70887ebb.js"><link rel="prefetch" href="/assets/js/226.e683c623.js"><link rel="prefetch" href="/assets/js/227.06f8bc32.js"><link rel="prefetch" href="/assets/js/228.82faf31a.js"><link rel="prefetch" href="/assets/js/229.0f8a6911.js"><link rel="prefetch" href="/assets/js/23.8da30b89.js"><link rel="prefetch" href="/assets/js/231.34717d1d.js"><link rel="prefetch" href="/assets/js/232.c7857239.js"><link rel="prefetch" href="/assets/js/233.6b7bcffd.js"><link rel="prefetch" href="/assets/js/234.0e0da6a5.js"><link rel="prefetch" href="/assets/js/235.5bc065c0.js"><link rel="prefetch" href="/assets/js/236.3e91ceb0.js"><link rel="prefetch" href="/assets/js/237.9116740e.js"><link rel="prefetch" href="/assets/js/238.8c792409.js"><link rel="prefetch" href="/assets/js/239.b4d8dfb8.js"><link rel="prefetch" href="/assets/js/24.3014a3d4.js"><link rel="prefetch" href="/assets/js/240.a1e61d58.js"><link rel="prefetch" href="/assets/js/241.3c016709.js"><link rel="prefetch" href="/assets/js/242.f8620e3f.js"><link rel="prefetch" href="/assets/js/243.8f53f134.js"><link rel="prefetch" href="/assets/js/244.424903c4.js"><link rel="prefetch" href="/assets/js/245.96c86aae.js"><link rel="prefetch" href="/assets/js/25.03ca3aa9.js"><link rel="prefetch" href="/assets/js/26.4916e6b8.js"><link rel="prefetch" href="/assets/js/27.f9aab712.js"><link rel="prefetch" href="/assets/js/28.1dfbff97.js"><link rel="prefetch" href="/assets/js/29.f7a69544.js"><link rel="prefetch" href="/assets/js/30.e3062801.js"><link rel="prefetch" href="/assets/js/31.a510760d.js"><link rel="prefetch" href="/assets/js/32.7d281288.js"><link rel="prefetch" href="/assets/js/33.6ee8ebed.js"><link rel="prefetch" href="/assets/js/34.b32e8d79.js"><link rel="prefetch" href="/assets/js/35.59d10d28.js"><link rel="prefetch" href="/assets/js/36.e1bcc1a4.js"><link rel="prefetch" href="/assets/js/37.f6c202dd.js"><link rel="prefetch" href="/assets/js/38.f8d5161a.js"><link rel="prefetch" href="/assets/js/39.1b4b64a0.js"><link rel="prefetch" href="/assets/js/4.77ea1544.js"><link rel="prefetch" href="/assets/js/40.efb0ab3f.js"><link rel="prefetch" href="/assets/js/41.85c7d269.js"><link rel="prefetch" href="/assets/js/42.36b0df70.js"><link rel="prefetch" href="/assets/js/43.c3cc85ee.js"><link rel="prefetch" href="/assets/js/44.b1575b98.js"><link rel="prefetch" href="/assets/js/45.8de97fe3.js"><link rel="prefetch" href="/assets/js/46.1fe43d4f.js"><link rel="prefetch" href="/assets/js/47.70a2e6cc.js"><link rel="prefetch" href="/assets/js/48.bb81e90c.js"><link rel="prefetch" href="/assets/js/49.8f4841fa.js"><link rel="prefetch" href="/assets/js/5.b3344219.js"><link rel="prefetch" href="/assets/js/50.e7216bda.js"><link rel="prefetch" href="/assets/js/51.1a2faa73.js"><link rel="prefetch" href="/assets/js/52.f625df74.js"><link rel="prefetch" href="/assets/js/53.b0067c47.js"><link rel="prefetch" href="/assets/js/54.0c85623e.js"><link rel="prefetch" href="/assets/js/55.491eeca5.js"><link rel="prefetch" href="/assets/js/56.8c9ffe2c.js"><link rel="prefetch" href="/assets/js/57.51902d8c.js"><link rel="prefetch" href="/assets/js/58.6d40a504.js"><link rel="prefetch" href="/assets/js/59.dbb8914b.js"><link rel="prefetch" href="/assets/js/6.a7455cf0.js"><link rel="prefetch" href="/assets/js/60.99f5caf1.js"><link rel="prefetch" href="/assets/js/61.ad9ebd9b.js"><link rel="prefetch" href="/assets/js/62.8c2c2783.js"><link rel="prefetch" href="/assets/js/63.2334b133.js"><link rel="prefetch" href="/assets/js/64.c79651bc.js"><link rel="prefetch" href="/assets/js/65.791edb2c.js"><link rel="prefetch" href="/assets/js/66.bd09db30.js"><link rel="prefetch" href="/assets/js/67.1311433b.js"><link rel="prefetch" href="/assets/js/68.8be881a0.js"><link rel="prefetch" href="/assets/js/69.f9bb1936.js"><link rel="prefetch" href="/assets/js/7.274fc010.js"><link rel="prefetch" href="/assets/js/70.77e0e02e.js"><link rel="prefetch" href="/assets/js/71.da2cc493.js"><link rel="prefetch" href="/assets/js/72.f4a80206.js"><link rel="prefetch" href="/assets/js/73.8d4c37c8.js"><link rel="prefetch" href="/assets/js/74.7a7304d5.js"><link rel="prefetch" href="/assets/js/75.2e6d01bf.js"><link rel="prefetch" href="/assets/js/76.7de509a7.js"><link rel="prefetch" href="/assets/js/77.e5e58459.js"><link rel="prefetch" href="/assets/js/78.1590a03f.js"><link rel="prefetch" href="/assets/js/79.a96442ae.js"><link rel="prefetch" href="/assets/js/8.26184cc0.js"><link rel="prefetch" href="/assets/js/80.76d4faa5.js"><link rel="prefetch" href="/assets/js/81.c79d5483.js"><link rel="prefetch" href="/assets/js/82.47926428.js"><link rel="prefetch" href="/assets/js/83.ec12a53e.js"><link rel="prefetch" href="/assets/js/84.72120681.js"><link rel="prefetch" href="/assets/js/85.30643e8b.js"><link rel="prefetch" href="/assets/js/86.64375c3f.js"><link rel="prefetch" href="/assets/js/87.7a86109f.js"><link rel="prefetch" href="/assets/js/88.68858482.js"><link rel="prefetch" href="/assets/js/89.00d57e24.js"><link rel="prefetch" href="/assets/js/9.56db4e9b.js"><link rel="prefetch" href="/assets/js/90.b7f9de16.js"><link rel="prefetch" href="/assets/js/91.e9a8e6fb.js"><link rel="prefetch" href="/assets/js/92.0b986faf.js"><link rel="prefetch" href="/assets/js/93.7c26025a.js"><link rel="prefetch" href="/assets/js/94.c39f793d.js"><link rel="prefetch" href="/assets/js/95.b74865a0.js"><link rel="prefetch" href="/assets/js/96.62558dca.js"><link rel="prefetch" href="/assets/js/97.945f9035.js"><link rel="prefetch" href="/assets/js/98.be789959.js"><link rel="prefetch" href="/assets/js/99.1adf100e.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8c3033ea.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-cd01cc30><div data-v-cd01cc30><div id="loader-wrapper" class="loading-wrapper" data-v-4cd7a24a data-v-cd01cc30 data-v-cd01cc30><div class="loader-main" data-v-4cd7a24a><div data-v-4cd7a24a></div><div data-v-4cd7a24a></div><div data-v-4cd7a24a></div><div data-v-4cd7a24a></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-623c7d26 data-v-cd01cc30 data-v-cd01cc30><h3 class="title" style="display:none;" data-v-623c7d26 data-v-623c7d26>自由·生活</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-623c7d26 data-v-623c7d26><input type="password" value="" data-v-623c7d26> <span data-v-623c7d26>Konck! Knock!</span> <button data-v-623c7d26>OK</button></label> <div class="footer" style="display:none;" data-v-623c7d26 data-v-623c7d26><span data-v-623c7d26><i class="iconfont reco-theme" data-v-623c7d26></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-623c7d26>vuePress-theme-reco</a></span> <span data-v-623c7d26><i class="iconfont reco-copyright" data-v-623c7d26></i> <a data-v-623c7d26><span data-v-623c7d26>丶忆yu'man</span>
            
          <span data-v-623c7d26>2020 - </span>
          2021
        </a></span></div></div> <div class="hide" data-v-cd01cc30><header class="navbar" data-v-cd01cc30><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/images/avatar.jpg" alt="自由·生活" class="logo"> <span class="site-name">自由·生活</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间轴
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="iconfont undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/ML&amp;DL/" class="nav-link"><i class="iconfont undefined"></i>
  ML&amp;DL
</a></li><li class="dropdown-item"><!----> <a href="/categories/力扣仓库/" class="nav-link"><i class="iconfont undefined"></i>
  力扣仓库
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="iconfont undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/开发工具/" class="nav-link"><i class="iconfont undefined"></i>
  开发工具
</a></li><li class="dropdown-item"><!----> <a href="/categories/学习笔记/" class="nav-link"><i class="iconfont undefined"></i>
  学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/categories/影视/" class="nav-link"><i class="iconfont undefined"></i>
  影视
</a></li><li class="dropdown-item"><!----> <a href="/categories/码农生涯/" class="nav-link"><i class="iconfont undefined"></i>
  码农生涯
</a></li><li class="dropdown-item"><!----> <a href="/categories/生活随笔/" class="nav-link"><i class="iconfont undefined"></i>
  生活随笔
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-document"></i>
      教程
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/course/blog/" class="nav-link"><i class="iconfont undefined"></i>
  博客系列教程
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-menu"></i>
      关联平台
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/docs/about/" class="nav-link"><i class="iconfont reco-account"></i>
  关于我
</a></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-cd01cc30></div> <aside class="sidebar" data-v-cd01cc30><div class="personal-info-wrapper" data-v-2a0ed2ae data-v-cd01cc30><img src="/images/avatar.jpg" alt="author-avatar" class="personal-img" data-v-2a0ed2ae> <h3 class="name" data-v-2a0ed2ae>
    丶忆yu'man
  </h3> <div class="num" data-v-2a0ed2ae><div data-v-2a0ed2ae><h3 data-v-2a0ed2ae>217</h3> <h6 data-v-2a0ed2ae>文章</h6></div> <div data-v-2a0ed2ae><h3 data-v-2a0ed2ae>15</h3> <h6 data-v-2a0ed2ae>标签</h6></div></div> <hr data-v-2a0ed2ae></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间轴
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="iconfont undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/ML&amp;DL/" class="nav-link"><i class="iconfont undefined"></i>
  ML&amp;DL
</a></li><li class="dropdown-item"><!----> <a href="/categories/力扣仓库/" class="nav-link"><i class="iconfont undefined"></i>
  力扣仓库
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="iconfont undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/开发工具/" class="nav-link"><i class="iconfont undefined"></i>
  开发工具
</a></li><li class="dropdown-item"><!----> <a href="/categories/学习笔记/" class="nav-link"><i class="iconfont undefined"></i>
  学习笔记
</a></li><li class="dropdown-item"><!----> <a href="/categories/影视/" class="nav-link"><i class="iconfont undefined"></i>
  影视
</a></li><li class="dropdown-item"><!----> <a href="/categories/码农生涯/" class="nav-link"><i class="iconfont undefined"></i>
  码农生涯
</a></li><li class="dropdown-item"><!----> <a href="/categories/生活随笔/" class="nav-link"><i class="iconfont undefined"></i>
  生活随笔
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-document"></i>
      教程
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/course/blog/" class="nav-link"><i class="iconfont undefined"></i>
  博客系列教程
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-menu"></i>
      关联平台
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/zhiyi-He" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/docs/about/" class="nav-link"><i class="iconfont reco-account"></i>
  关于我
</a></div> <!----></nav> <ul class="sidebar-links"><li><a href="/blogs/%E7%A0%81%E5%86%9C%E7%94%9F%E6%B6%AF/" aria-current="page" class="sidebar-link">码农生涯</a></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>码农生涯</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/blogs/码农生涯/interview/java-interview-questions.html" class="sidebar-link">Java面试题</a></li><li><a href="/blogs/码农生涯/interview/算法.html" class="sidebar-link">算法</a></li><li><a href="/blogs/码农生涯/interview/Java基础.html" class="active sidebar-link">Java基础</a></li><li><a href="/blogs/码农生涯/interview/计算机网络.html" class="sidebar-link">计算机网络</a></li><li><a href="/blogs/码农生涯/interview/数据库.html" class="sidebar-link">数据库</a></li><li><a href="/blogs/码农生涯/interview/JVM虚拟机.html" class="sidebar-link">JVM虚拟机</a></li><li><a href="/blogs/码农生涯/interview/多线程.html" class="sidebar-link">多线程</a></li><li><a href="/blogs/码农生涯/interview/操作系统.html" class="sidebar-link">操作系统</a></li><li><a href="/blogs/码农生涯/interview/redis.html" class="sidebar-link">redis</a></li><li><a href="/blogs/码农生涯/interview/Spring.html" class="sidebar-link">Spring</a></li><li><a href="/blogs/码农生涯/interview/Linux.html" class="sidebar-link">Linux</a></li><li><a href="/blogs/码农生涯/interview/设计模式.html" class="sidebar-link">设计模式</a></li><li><a href="/blogs/码农生涯/interview/开放问题.html" class="sidebar-link">开放问题</a></li></ul></section></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-623c7d26 data-v-cd01cc30><h3 class="title" style="display:none;" data-v-623c7d26 data-v-623c7d26>Java基础</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-623c7d26 data-v-623c7d26><input type="password" value="" data-v-623c7d26> <span data-v-623c7d26>Konck! Knock!</span> <button data-v-623c7d26>OK</button></label> <div class="footer" style="display:none;" data-v-623c7d26 data-v-623c7d26><span data-v-623c7d26><i class="iconfont reco-theme" data-v-623c7d26></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-623c7d26>vuePress-theme-reco</a></span> <span data-v-623c7d26><i class="iconfont reco-copyright" data-v-623c7d26></i> <a data-v-623c7d26><span data-v-623c7d26>丶忆yu'man</span>
            
          <span data-v-623c7d26>2020 - </span>
          2021
        </a></span></div></div> <div data-v-cd01cc30><main class="page"><div class="page-title" style="display:none;"><h1 class="title">Java基础</h1> <div data-v-8bc6ae5c><i class="iconfont reco-account" data-v-8bc6ae5c><span data-v-8bc6ae5c>丶忆yu'man</span></i> <i class="iconfont reco-date" data-v-8bc6ae5c><span data-v-8bc6ae5c>2021-03-31</span></i> <i class="iconfont reco-eye" data-v-8bc6ae5c><span id="/blogs/%E7%A0%81%E5%86%9C%E7%94%9F%E6%B6%AF/interview/Java%E5%9F%BA%E7%A1%80.html" data-flag-title="Your Article Title" class="leancloud-visitors" data-v-8bc6ae5c><a class="leancloud-visitors-count" style="font-size:.9rem;font-weight:normal;color:#999;"></a></span></i> <i class="iconfont reco-tag tags" data-v-8bc6ae5c><span class="tag-item" data-v-8bc6ae5c>面试</span></i></div></div> <div class="theme-reco-content content__default" style="display:none;"><div class="custom-block tip"><p>Java好难，面试让我明白了</p></div> <h1 id="java基础">Java基础</h1> <h2 id="语法">语法</h2> <h3 id="java和c-的区别">Java和C++的区别</h3> <ul><li>C++有指针，Java中没有，Java中的是引用类型，并且能够自动进行内存管理</li> <li>C++需要手动内存回收，而Java是通过JVM自动GC</li> <li>C++能够直接编译为机器指令，而Java是编译为字节码class文件，然后通过解释器转成机器指令</li> <li>C++相对Java而言更快，但是Java可以通过JVM实现跨平台</li> <li>Java纯面向对象，而C++有一部分面向过程，例如全局变量</li> <li>C++支持多继承，而Java只支持单继承，但是Java能够有实现方法</li> <li>C++运算符可以重载，而Java中不行</li> <li>C++异常很少，而Java中有丰富的异常类型</li></ul> <h3 id="java1-8特性-用过哪些">Java1.8特性，用过哪些？</h3> <h3 id="final关键字-初始化的方式">final关键字，初始化的方式</h3> <ol><li>final关键字
<ul><li>修饰变量：修饰变量时代表这是一个不可变变量，修饰静态变量时需要在类加载初始化时赋值，而修饰实例变量时需要在实例化时进行赋值。</li> <li>修饰方法内参数变量：表示在这个方法内部，也就是变量的生命周期内无法改变值。</li> <li>修饰方法：表示这个方法不能被重写。</li> <li>修饰类：表示这个类不能被继承。</li></ul></li> <li>修饰实例变量时初始化的方式
<ul><li>直接在类中赋值：final int a = 1。</li> <li>在默认构造器中进行赋值</li> <li>在代码块中进行赋值</li></ul></li></ol> <h3 id="static关键字">static关键字</h3> <ul><li>修饰变量：表示这个变量可被实例对象共享。</li> <li>修饰方法：这个方法能够被直接通过“类名.方法名”进行调用。</li> <li>修饰静态代码块：代码块中的内容只会在类加载初始化阶段执行一次</li> <li>修饰内部类</li></ul> <h3 id="浅拷贝和深拷贝">浅拷贝和深拷贝</h3> <ol><li><p>浅拷贝和深拷贝的区别</p> <p>对于一个Java对象，浅拷贝只会拷贝对象中的基本数据类型，而对引用类型只会传递它的引用地址，并没有实际创建一个对象</p> <p>而深拷贝不仅会拷贝基本数据类型，还会拷贝引用类型对象。</p></li> <li><p>clone方法</p> <p>clone方法只会对当前对象时间浅拷贝，并不会拷贝其中引用类型。</p></li> <li><p>怎样实现深拷贝</p> <ul><li>多次clone，对Java对象的引用类型变量也实现clone方法</li> <li>使用序列化的方法，重写序列化中的读写序列化规则，在写的时候将对象写入，读的时候在还原为原对象</li></ul></li></ol> <h3 id="和equals的区别">== 和equals的区别</h3> <ul><li><p>==对基本数据类型进行比较时，只会比较它们的值，而对引用数据类型进行比较时，只会比较它们的地址</p></li> <li><p>equals方法继承自Object类，而Object类中的equals方法默认实际就是==，对于引用类型也只是会比较它们的地址</p> <p>而Java中有很多类都重写了equals方法，例如String类、File类等，在String类中，equals方法会在类型相等的基础上，比较两个对象的内容是否相同。</p></li></ul> <h3 id="重写equals方法应该注意什么">重写equals方法应该注意什么</h3> <h3 id="什么时候重写equals-什么时候重写hashcode">什么时候重写equals，什么时候重写HashCode</h3> <ul><li>在判断两个对象是否内容一致时需要重写equals方法，接上区别</li> <li>使用Map、Set等集合类时，需要重写HashCode方法，equals方法和HashCode的关系：
<ul><li>equals相等时，HashCode一定相等</li> <li>equals不相等时，HashCode不一定不相等</li> <li>HashCode相等时，equals不一定相等</li> <li>HashCode不相等时，equals一定不相等</li></ul></li></ul> <h3 id="string三大件">String三大件</h3> <ul><li>String：String对象是一个 不可变字符串，底层采用final关键字修饰char数组</li> <li>StringBuilder：是一个可变字符串对象，能够使用append()方法在后面添加</li> <li>StringBuffer：是一个可变字符串对象，并且是线程安全的，内部采用Syncronized修饰了方法</li></ul> <p>当修改和拼接操作少时，使用String对象，当修改和拼接操作多时，使用StringBuilder对象，如果操作多并且要实现线程安全时，使用StringBuffer对象。</p> <h3 id="string为什么final修饰">String为什么final修饰</h3> <ul><li>第一，为了实现字符串池，只有String对象不可变时，才能够实现，否则一个引用对字符串进行修改，其它引用全会修改。</li> <li>第二，为了线程安全，不可变时就代表线程安全</li> <li>第三，为了实现HashCode不变性，String对象不可变时，HashCode值也不会变</li></ul> <h3 id="重载和重写的区别">重载和重写的区别</h3> <ul><li>重载：重载是对同一个类中的同名方法，这些方法有相同的方法名，但是可以有不用的参数以及参数类型，是一种静态分派，类加载时期确定，属于一种编译器的多态。</li> <li>重写：重写是对有继承关系类的同名方法，这些方法的参数以及返回值都必须相同，是一种动态分派，是一种运行期的多态。</li></ul> <h3 id="静态分派和动态分派">静态分派和动态分派</h3> <ul><li>静态分派：根据静态类型来确定方法的分派，发生在编译时期，典型应用是方法的重载，</li> <li>动态分派：根据实际类型来确定方法的分派，发生在运行期间，典型应用是方法的重写。主要就是父类引用能够指向子类对象，父类引用能够调用子类的方法。</li></ul> <h3 id="object中有哪些方法">Object中有哪些方法</h3> <p>clone()、finalize()、equals()、hashCode()、wait()、notify()、notifyAll()、sleep()、toString()、getClass()</p> <h2 id="java-io">Java IO</h2> <h3 id="详述io">详述IO</h3> <h3 id="bio、nio、aio">BIO、NIO、AIO</h3> <h3 id="源码执行的全过程">源码执行的全过程</h3> <h2 id="集合">集合</h2> <h3 id="详述集合">详述集合</h3> <h3 id="arraylist和linkedlist的区别">ArrayList和LinkedList的区别</h3> <ul><li><p>数据结构上：ArrayList底层采用的是数组实现，而LinkedList是采用双向链表进行实现</p></li> <li><p>插入删除：ArrayList默认的add()是会插入到数组最后一个元素的后面，也就是那个实际元素后面，而指定位置插入或删除的add()方法需要将后面的元素向前或向后移动一个单位，比较耗时，而LinkedList是采用的双向链表进行实现，因此插入删除时只需要找到指定位置，然后断链或者链接就可以实现。</p></li> <li><p>查询：LinkedList不支持高效的随机访问，而ArrayList采用数组可以实现。</p></li> <li><p>空间：ArrayList因为是实现动态数组的效果，因此在数组中会预留一部分空间用于元素插入，会浪费空间，并且需要扩容</p> <p>而LinkedList空间上虽然可以实现近似无限大，但是对于每个结点都需要存储前驱结点和后继结点的指针</p></li></ul> <h3 id="arraylist扩容过程">ArrayList扩容过程</h3> <ul><li><p>首先看看ArrayList的初始化，ArrayList默认初始化时只会创建一个空数组，并不会分配空间，当有元素插入时，才会扩容。</p></li> <li><p>扩容过程：当插入一个元素后，在add()方法中会对当前容量和插入所需的容量进行比较，当容量不足时就会使用grow()方法进行扩容</p> <p>在grow()中，会对原来容量进行右移的位操作，然后再加上原来容量，这样就实现了容量扩大到近似1.5倍，之后将原来的数组拷贝到新容量的数组上。</p> <p>ArrayList扩容过程中拷贝是浅拷贝。</p></li></ul> <h3 id="hashmap底层实现">HashMap底层实现</h3> <p>HashMap底层是采用数组加链表实现的，当实例化一个HashMap时，会创建一个Entry数组，数组的长度称为容量，每个Entry元素都可以看作为一个桶，对于每个桶都建立了索引，所以HashMap能够通过索引快速查询桶中的元素，桶内是以链表的形式存在的，当put一条数据时，先计算键的hash值，然后插入对应桶的链表后面，这里插入1.8版本前是头插法，1.8就改为了尾插法。</p> <h3 id="为什么hashmap初始化16-为什么长度大于8转为红黑树">为什么hashmap初始化16，为什么长度大于8转为红黑树</h3> <ol><li><p>hashMap初始化16（2的倍数）</p> <p>首先初始化为2的倍数主要是方便通过hash值计算存放的位置。</p> <p>​	例如长度16，长度减1后为15，二进制就为1111，然后直接跟hash值进行&amp;操作能够直接得到存放的索引，速度非常快。</p> <p>另外长度为2的倍数也方便进行rehash，在1.8版本时hashMap扩容时不再需要rehash，直接判断扩容的位是1还是0就可以直接算出扩容后的hash索引位置</p> <p>​	例如长度16，扩容后为32，二进制右移1位，直接&amp;操作就可以得到扩容后应该存放的索引位置。</p></li> <li><p>长度大于8转为红黑树</p> <p>链表长度大于8转为红黑树，主要是在链表长度短时查询插入效率更好，但是长度大于8后红黑树的性能就更优了。</p></li></ol> <h3 id="hashmap怎样解决冲突">HashMap怎样解决冲突</h3> <p>首先HashMap是采用链地址法解决冲突的，插入数据时，计算键的hash值，当发生冲突时直接插入到链表的后面</p> <p>另外还有其它的解决办法：例如开放地址法（发生冲突时直接加增量）、再哈希法（使用另外的hash函数）、建立公共溢出区</p> <h3 id="hashmap并发问题-怎样实现线程安全">HashMap并发问题，怎样实现线程安全</h3> <p>两个并发问题：</p> <ul><li>第一个是并发插入问题，多个线程同时对HashMap进行put操作，此时这两个插入操作又发生了碰撞，需要插入到同一个桶的链表中，此时就会最终导致只有一个线程的插入会成功，另一个会被覆盖。</li> <li>第二个是<a href="https://blog.csdn.net/bjwfm2011/article/details/81076736" target="_blank" rel="noopener noreferrer">并发扩容问题<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>，主要是两个线程同时来插入，恰好这时HashMap达到了扩容条件，因此两个线程都会对HashMap扩容一倍，假设其中一个线程遍历到了某元素，然后挂起了，另一个线程执行完了resize过程，当线程再次运行时，扩容自己的HashMap时就会产生环，这个主要感觉还是1.8版本前链表采用的是头插法，所以出现了这个问题。</li> <li>另外应该还可以说一个并发插入问题，多个线程插入触发扩容，但是最终只会有一个线程扩容成功并进行赋值，因此其它线程的插入还是失败了。</li></ul> <h3 id="红黑树的特性-红黑树和avl的区别-为什么不使用avl树">红黑树的特性？红黑树和AVL的区别？为什么不使用AVL树？</h3> <ol><li>红黑树的特性
<ul><li>红黑树的根节点为黑色</li> <li>红黑树结点除了黑色就是红色</li> <li>红结点的左右结点全为黑色</li> <li>叶子结点全为黑色</li> <li>任意结点到它的叶子结点路径上的黑色结点数目都是相同的</li> <li>红黑树其实就是一个二叉平衡搜索树</li></ul></li> <li>红黑树和平衡二叉树的区别
<ul><li>平衡要求：红黑树并不追求“完全平衡”，降低了对旋转的要求，保证的是结点的颜色，因此性能相比AVL更高。</li> <li>插入删除：红黑树插入删除最多会经历3次的旋转，O(1)的复杂度，远比AVL树简单，对插入、删除、更新操作进行平衡。</li> <li>应用：当查询的次数大于插入、删除时，选择AVL树，三者操作差不多时可以选择红黑树。</li></ul></li></ol> <h3 id="hashset去重原理">HashSet去重原理</h3> <p>本质上是重写equals()和HashCode()方法来实现去重。<a href="https://blog.csdn.net/ColinChen1996/article/details/77887539" target="_blank" rel="noopener noreferrer">去重过程<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <p>HashSet底层实际上是利用一个HashMap进行实现的，我们可以看看HashSet的add()方法</p> <p>当set进行插入时，会调用add方法，然后在hashMap中put一个以当前插入元素为key，默认对象为值的Entry元素。</p> <p>另外去重的过程是利用了equals()和HashCode()方法，先判断hash值是否相等，相等再使用= =进行比较基本数据类型值或地址值，相等代表就是重复值，另外= =号未比较出来，就会使用equals()进行比较对象内容，相等也代表重复。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">boolean</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">E</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span> 
            <span class="token keyword">return</span> map<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span>e<span class="token punctuation">,</span> PRESENT<span class="token punctuation">)</span><span class="token operator">==</span><span class="token keyword">null</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>    
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token comment">// 去重</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>e<span class="token punctuation">.</span>hash <span class="token operator">==</span> hash <span class="token operator">&amp;&amp;</span> <span class="token punctuation">(</span><span class="token punctuation">(</span>k <span class="token operator">=</span> e<span class="token punctuation">.</span>key<span class="token punctuation">)</span> <span class="token operator">==</span> key <span class="token operator">||</span> key<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>k<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>

<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="异常">异常</h2> <h3 id="详述异常">详述异常</h3> <p>当出现异常时，JVM会建立相关对象并且将异常信息抛给调用者，由调用者决定是否对其进行处理，如果没有进行捕获的话，就继续将这个异常信息抛给JVM，由虚拟机将信息打印在控制台上。异常分类主要可以分为运行时异常和编译时异常（也称为非运行时异常），编译时异常必须对它进行捕获处理，主要有SQL Exception和IO Exception两种异常类，而运行时异常一般时由于程序逻辑错误引起的，通常不需要捕获，出现这种异常会直接让程序停止执行。</p> <h3 id="运行时异常和非运行时异常的区别">运行时异常和非运行时异常的区别</h3> <h3 id="运行时异常有哪些">运行时异常有哪些</h3> <h3 id="exception和error的区别">Exception和error的区别</h3></div> <footer class="page-edit" style="display:none;"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">2021/5/22 下午7:12:29</span></div></footer> <!----> <!----> <!----></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c8d125c6 data-v-c8d125c6><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c8d125c6><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c8d125c6></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c8d125c6></path></svg></div><APlayer audio="" fixed="true" mini="true" theme="#b7daff" loop="loop" order="random" preload="auto" volume="0.08" mutex="true" lrc-type="0" list-folded="true" list-max-height="250" storage-name="vuepress-plugin-meting" id="aplayer-fixed"></APlayer></div></div>
    <script src="/assets/js/app.0e76bb72.js" defer></script><script src="/assets/js/3.c5829877.js" defer></script><script src="/assets/js/1.695f3f80.js" defer></script><script src="/assets/js/230.f895ca67.js" defer></script>
  </body>
</html>
